class_name PlayerGroundState
extends StateMachine


func _init() -> void:
	super("ground")


func _on_setup() -> void:
	add_state(PlayerIdleState.new())
	add_state(PlayerWalkState.new())
	add_state(PlayerRunState.new())
	add_state(PlayerBasicAttack.new())
	add_state(PlayerChargedAttack.new())
	
	var ground_multiway_transition := MultiwayStateTransition.new(
		"ground_transition",
		[
			func(): return\
				2 if owner.input_handler.is_action_double_click_started_any(["move_left", "move_right"] as Array[String]) else\
				1 if owner.input_handler.is_action_pressed_any(["move_left", "move_right"] as Array[String]) else\
				0
		],
		{
			[0]: "idle",
			[1]: "walk",
			[2]: "run",
		}
	)
	add_transition("ghost", ground_multiway_transition)
	add_transition("idle", ground_multiway_transition)
	add_transition("walk", ground_multiway_transition)
	add_transition("run", ground_multiway_transition)
	add_transition("any", ConditionStateTransition.new(
		"basic_attack_transition",
		"basic_attack",
		func(): return owner.input_handler.is_action_just_pressed("attack"),
		func(): pass
	))
	add_transition("any", ConditionStateTransition.new(
		"charged_attack_transition",
		"charged_attack",
		func(): return owner.input_handler.is_action_long_pressed("attack"),
		func(): pass
	))
